var currentImg = 0;
$(document).ready(function(){

	var picCount1 = 0;
	var picCount2 = 1;

	$(window).resize(function(){
		setBackground();
		//$(".float-div").css(".")
		var nameWidthValue = parseInt($(".name1").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
		$(".project").css("left",(nameWidthValue)+"px");
	});
	setBackground();
	$(".weixin-img").mouseenter(function(e){
		$(".code-for-weixin").show();
	});
	$(".weixin-img").mouseleave(function(e){
		$(".code-for-weixin").hide();
	});
	//设置preject标签左偏移
	var nameWidthValue = parseInt($(".name1").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
	$(".project").css("left",(nameWidthValue)+"px");

	var canMoveMouseFlag = true;
	$(".for-left-nav").mouseenter(function(e){
		if(canMoveMouseFlag){
			canMoveMouseFlag = false;
			$(".nav-top").animate({left: '266px'}, "slow");
			$(".nav-bottom").animate({left: '266px'}, "slow",function(){
				canMoveMouseFlag = true;
			});
		}
		$(".menu a").css("background","url(res/menu2.png) no-repeat");
		$(".menu a").css("background-position","right center");
	});
	$(".left-nav").mouseleave(function(e){
		if(canMoveMouseFlag){
			canMoveMouseFlag = false;
			$(".nav-top").animate({left: '158px'}, "slow");
			$(".nav-bottom").animate({left: '-7px'}, "slow",function(){
				canMoveMouseFlag = true;
			});	
		}
		$(".menu a").css("background","url(res/menu.png) no-repeat");
		$(".menu a").css("background-position","right center");
	});

	//切换背景
	changeBackground(picCount1,picCount2);
	//展示信息详情
	//切换背景

	var flag = 0;
	var flagShowP = 0;
	$(".plus a").click(function(){
		if (flag == 0) {
			$(".sub-name").css("display","block");
			$(".sub-name").animate({top: '255px'}, "slow");
			$(".plus").animate({top: '470px'}, "slow",function(){
				$(".name-info p:eq("+$("#surprised").find(".showNow").index()+")").css("display","block");				
				$(".name-info").fadeIn(500);
			});
			$(".plus a").html("-");
			flag = 1;
		}else{
			$(".name-info").fadeOut(500,function(){
				$(".name-info p:eq("+$("#surprised").find(".showNow").index()+")").css("display","none");
				$(".sub-name").css("display","none");
				$(".sub-name").animate({top: '227px'}, "slow");	
				$(".plus").animate({top: '253px'}, "slow");
				$(".plus a").html("+");
				flag = 0;
			});
		}
	});
});
//展示name-info内容
function showNameInfo(){
	$(".name-info p").fadeIn(1000);
}
//name-info元素收回动画
function transMinNameInfo(){
	var nameInfoWidth = 458;
	var timerN = setInterval(runT,50);
		function runT(){
			nameInfoWidth = nameInfoWidth - 15;
			$(".name-info").css("width",nameInfoWidth+"px");
			if(nameInfoWidth <= 72){
				clearInterval(timerN);
			}
		}
	
}
//name-info元素变形动画
function transNameInfo(){
	var nameInfoWidth = 72;
	var timerN = setInterval(runT,50);
	function runT(){
		nameInfoWidth = nameInfoWidth + 15;
		$(".name-info").css("width",nameInfoWidth+"px");
		if(nameInfoWidth >= 458){
			clearInterval(timerN);
		}
	}
}
function changeBackground(picCount1,picCount2){
	var i = 0;
	//标签计数
	var j = 1;
	var maxWidth = $(window).width();
	console.log(maxWidth);
	var timer = setInterval(changeBackImg,5);
	var listLeng = $("#surprised li").length;
	var curentNum = 0;
	function changeBackImg(){
		//alert(i);
		i = i + 1;
		if(i>maxWidth){
			if( picCount1 == listLeng){
				picCount1 = 0;
				$("#surprised li:eq("+picCount1+")").removeClass("showNow");
				setVis($("#surprised li:eq("+picCount1+")").find("img"));
				$(".name a:eq("+picCount1+")").css("display","none");
				$(".name-info p:eq("+picCount1+")").css("display","none");
				picCount1 = picCount1 + 1;
				
			}else{
				$("#surprised li:eq("+picCount1+")").removeClass("showNow");
				setVis($("#surprised li:eq("+picCount1+")").find("img"));
				$(".name a:eq("+picCount1+")").css("display","none");
				$(".name-info p:eq("+picCount1+")").css("display","none");
				picCount1 = picCount1 + 1;
			}
			currentImg = picCount1;
			if(picCount2 == listLeng){
				picCount2 = 0;
				$("#surprised li:eq("+picCount2+")").addClass("showNow");
				setOpa($("#surprised li:eq("+picCount2+")").find("img"));
				$(".name a:eq("+picCount2+")").css("display","block");
				$(".name-info p:eq("+picCount2+")").css("display","block");
				picCount2 = picCount2 + 1;
			}else{
				$("#surprised li:eq("+picCount2+")").addClass("showNow");
				setOpa($("#surprised li:eq("+picCount2+")").find("img"));
				$(".name a:eq("+picCount2+")").css("display","block");
				$(".name-info p:eq("+picCount2+")").css("display","block");
				picCount2 = picCount2 + 1;
			}
			i = 0;
			if( j == listLeng){
				j = 0;
				var nameWidthValue = parseInt($(".name1").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
				$(".project").css("left",(nameWidthValue)+"px");
				j = j + 1;
			}else{
				var nameWidthValue = parseInt($(".name a:eq("+j+")").css("width")) + (document.documentElement.clientWidth*0.45) - 54;
				$(".project").css("left",(nameWidthValue)+"px");
				j = j + 1;
			}
		}
		$("#progress-bar").css("left",i+"px");
	}
}
//隐藏前一个元素
function setVis(imgDom){
	var opaImg = 1;
		var timerO = setInterval(runO,10);
		function runO(){
			imgDom.css("z-index","-30");
			opaImg = opaImg - 0.05;
			imgDom.css("opacity",opaImg);
			if(imgDom.css("opacity") == 0){
				clearInterval(timerO);
				imgDom.css("display","none");
			}
		}
}
//展示下一个元素
function setOpa(imgDom){
	var opaImg = 0;
		var timerO = setInterval(runO,10);
		function runO(){
			imgDom.css("z-index","-10");
			imgDom.css("display","block");
			opaImg = opaImg + 0.05;
			imgDom.css("opacity",opaImg);
			if(imgDom.css("opacity") == 1){
				clearInterval(timerO);
			}
		}
}
setBackground = function (){

	$("#surprised").width($(window).width());
	//$("#surprised").height($(window).height());
	$(".footer").height($(window).height()-381);
	if($(window).height() < 520){
		$(".footer").height(123);
	}
	
}
